package com.example.musicplayer.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.HorizontalScrollView;

public class NewHorizontalScrollView extends HorizontalScrollView {
    //设置能否滑动
    private boolean mCanScroll = true;

    public NewHorizontalScrollView(Context context) {
        super(context);
    }

    public NewHorizontalScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NewHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    //设置scrollview能否滑动
    public void setCanScroll(boolean canScroll) {
        mCanScroll = canScroll;
    }

    public boolean isCanScroll() {
        return mCanScroll;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (!mCanScroll) {
            return false;
        }
        return super.onInterceptTouchEvent(ev);
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (!mCanScroll) {
            return false;
        }
        return super.onTouchEvent(ev);
    }
}